export default {
  tree_in_invoice: {
    _odoo_model: 'ir.ui.view',
    model: 'fp.fapiao.in.invoice',
    type: 'tree',

    fields: {
      name: {},
      type: { string: '进销项类型' },
      invoice_type: { string: '种类' },
      state: { string: '状态' },
      company_id: { string: '公司' },

      buyer_name: { string: '购买方' },
      // buyer_tax_code: { string: '税号' },
      // buyer_address_phone: { string: '地址电话' },
      // buyer_bank_account: { string: '银行账户' },

      saler_name: { string: '销售方' },
      // saler_tax_code: { string: '税号' },
      // saler_address_phone: { string: '地址电话' },
      // saler_bank_account: { string: '银行账户' },

      // name: { string: '名称' },
      // payee_name: { string: '收款人' },
      // checker_name: { string: '复核' },
      // drawer_name: { string: '开票人' },

      type_code: { string: '发票代码' },
      code: { string: '发票号码' },
      // check_code: { string: '校验码' },
      date_order: { string: '开票日期' },
      // note: { string: '备注' },
      // amount_untaxed: { string: '不含税合计' },
      // amount_tax: { string: '税合计' },
      amount_total: { string: '价税合计' }
      // cn_amount_total: { string: '价税合计大写' }
    }
  },

  form_in_invoice: {
    _odoo_model: 'ir.ui.view',
    model: 'fp.fapiao.in.invoice',
    type: 'form',

    arch: {
      header: {
        buttons: [
          {
            name: 'action_confirm',
            string: '确认',
            type: 'object',
            btn_type: 'primary',
            invisible: ({ record }) => {
              const { state } = record
              return state !== 'draft'
            }
          },

          {
            name: 'action_post',
            string: '过账',
            type: 'object',
            btn_type: 'primary',
            invisible: ({ record }) => {
              const { state } = record
              return !['done', 'confirmed'].includes(state)
            }
          },

          {
            name: 'action_cancel',
            string: '取消',
            type: 'object',
            invisible: ({ record }) => {
              const { state } = record
              return state === 'cancel'
            }
          },
          {
            name: 'action_draft',
            string: '重置为草稿',
            type: 'object',
            invisible: ({ record }) => {
              const { state } = record
              return state !== 'cancel'
            }
          }
        ],
        fields: {
          state: {
            widget: 'statusbar',
            statusbar_visible: 'draft,confirmed,doing,done,posted'
          }
        }
      }
    },

    fields: {
      date_fapiao: { string: '开票日期' },

      type: { string: '进销项类型' },
      invoice_type: { string: '种类' },
      state: {
        string: '状态',
        selection: [
          ['draft', '草稿'],
          ['confirmed', '已确认'],
          ['doing', '查验中'],
          ['done', '已查验'],
          ['error', '查验失败'],
          ['posted', '已过账'],
          ['cancel', '已取消']
        ]
      },

      name: { string: '订单号码', readonly: 0 },

      company_id: { string: '公司' },
      // user_id: { string: '开票人' },

      attachment_id: { string: '原始单据', widget: 'attachment' },

      // partner_id: { string: '客户', required: 1 },

      buyer_name: { string: '购买方' },
      buyer_tax_code: { string: '税号' },
      buyer_phone: { string: '电话' },
      buyer_address: { string: '地址' },

      buyer_address_phone: { string: '地址电话' },
      buyer_bank_account: { string: '银行账户' },

      saler_name: { string: '销售方' },
      saler_tax_code: { string: '税号' },
      saler_phone: { string: '电话' },
      saler_address: { string: '地址' },
      saler_address_phone: { string: '地址电话' },
      saler_bank_account: { string: '银行账户' },

      payee_name: { string: '收款人' },
      checker_name: { string: '复核' },
      drawer_name: { string: '开票人' },

      type_code: { string: '发票代码' },
      code: { string: '发票号码' },
      check_code: { string: '校验码' },
      date_order: { string: '订单日期' },
      note: { string: '备注' },
      amount_untaxed: { string: '不含税合计' },
      amount_tax: { string: '税合计' },
      amount_total: { string: '价税合计' },
      cn_amount_total: { string: '价税合计大写' },

      line_ids: {
        widget: 'x2many_tree',
        context: {},
        string: '明细行',

        views: {
          tree: {
            fields: {
              // sequence: { string: '序号' },
              // name: { string: '说明' },
              line_type: {},
              product_categ_name: { string: '商品类别' },
              product_name: { string: '货物或应税劳务、服务名称' },
              product_spec: { string: '规格型号' },
              uom_name: { string: '单位' },

              quantity: { string: '数量' },
              price_unit: { string: '单价' },

              tax_ratio: { string: '税率' },
              // amount_discount: {},
              amount_untaxed: { string: '金额' },
              amount_tax: { string: '税额' }
              // amount_total: { string: '含税金额' }
            }
          },

          form: {
            fields: {
              type: { invisible: 1 },
              line_type: {},

              sequence: { string: '序号' },
              name: { string: '说明' },
              // product_id: { string: '产品', required: 1 },
              product_categ_code: { string: '商品类别编码' },

              product_categ_name: { string: '商品类别名称' },

              product_name: { string: '货物或应税劳务、服务名称' },
              product_spec: { string: '规格型号' },
              uom_name: { string: '单位' },

              quantity: { string: '数量' },
              price_unit: { string: '单价' },

              tax_ratio: { string: '税率' },
              // amount_discount: {},
              amount_untaxed: { string: '金额' },
              amount_tax: { string: '税额' }
              // amount_total: { string: '含税金额' }
            }
          }
        }
      }
    }
  },

  // search_in_fapiao: {
  //   _odoo_model: 'ir.ui.view',
  //   model: 'fp.fapiao.out.invoice',
  //   type: 'search',
  //   arch: {
  //     fields: {
  //       name: {
  //         filter_domain: self => {
  //           return [
  //             '|',
  //             ['saler_name', 'ilike', self],
  //             ['buyer_name', '=like', self],
  //             ['code', '=like', self]
  //           ]
  //         }
  //       }
  //     },

  //     filters: {
  //       group1: {
  //         draft: {
  //           string: '草稿',
  //           domain: [['state', '=', 'draft']]
  //         },
  //         posted: {
  //           string: '已查验',
  //           domain: [['state', '=', 'posted']]
  //         }
  //       },

  //       group2: {
  //         date: { string: '日期', date: 'date' }
  //       }
  //     }
  //   }
  // },

  action_in_fapiao: {
    _odoo_model: 'ir.actions',
    name: '进项发票',
    type: 'ir.actions.act_window',
    res_model: 'fp.fapiao.in.invoice',
    // search_view_id: 'search_in_fapiao',
    domain: [],
    context: {},
    views: {
      tree: 'tree_in_invoice',
      form: 'form_in_invoice'
    }
  }
}
